Skip to content

feat(prompt-hook): gate context injection by confidence tier - #145

Merged
sunerpy merged 1 commit into
mainfrom
feat/upstream-1.4.1-defer-f-prompt-hook-gate
Jul 14, 2026
Merged

sunerpy merged 1 commit into
mainfrom
feat/upstream-1.4.1-defer-f-prompt-hook-gate

Conversation

@sunerpy

@sunerpy sunerpy commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

Upstream-sync DEFER item F — ports the non-telemetry prompt-hook improvements from colby 1.2.0..1.4.1 (#1126 multilingual gate, #1138 stem bounding, #1136 graph-tier mechanics, #1144/#1145/#1146 segment integrity), as ONE golden-neutral feat: release. All telemetry EXCLUDED (maintainer decision — no-tracking posture).

codegraph prompt-hook was a bare forwarder that ran codegraph_explore on every prompt. It now injects context by a three-tier confidence gate:

  • HIGH — a structural question (multilingual, ~29 languages, inflections + multi-word phrases; call/trace/affect/connect stems bounded on the right so callus/Connecticut/affectionate don't fire) OR a graph-verified code token (inner camelCase / flanked underscore / call name( / member x.name; bare PascalCase is not a token) → full explore in a <codegraph_context> block.
  • MEDIUM — plain prose words matching indexed symbol-name segments (one name covering ≥2 prompt words, or a rare ≥4-char segment shared across ≥2 names) → short pointer naming the symbols, no explore.
  • otherwise silent.

Segment matching is derived at query time from existing indexed node names → no schema change (CURRENT_SCHEMA_VERSION stays 7, golden .schema byte-identical, no name_segment_vocab table). Parses the Claude UserPromptSubmit JSON {prompt,cwd} (raw-string invocation still works); CODEGRAPH_NO_PROMPT_HOOK / CODEGRAPH_PROMPT_HOOK=0 disable it.

Verification

  • make ci green (fmt + clippy + test + guardrail); schema_parity 4/4; equivalence 10/10.
  • 15 prompt-hook e2e + structural_gate/segments unit tests green (multilingual/Devanagari, inflection/phrase, what calls Counter() fires + ordinary-word negatives, JSON payload, Tier-A/Tier-B MEDIUM on a dedicated non-golden fixture, kill-switch).
  • Golden .schema + fixtures byte-identical, NO regen.
  • No telemetry/counter/tracking added. Only new dep: unicode-normalization (NFD folding; regex already transitive) — guardrail clean (not AI/vector/LLM).
  • Independent oracle review: APPROVE (all 7 risk axes verified; schema-neutral, deterministic, telemetry-free).

DEFER item F of the 1.2.0→1.4.1 upstream sync. Remaining: language expansions (Metal/CUDA, then from-scratch grammars).

Ports the non-telemetry prompt-hook improvements from upstream colby
1.2.0..1.4.1. `codegraph prompt-hook` was a bare forwarder that ran
codegraph_explore on every prompt; it now decides how much context to inject
by a three-tier confidence gate, so ordinary chatter no longer triggers a full
explore and non-code prompts stay silent.

- HIGH — a structural question (multilingual gate covering ~29 languages, with
  inflections and multi-word phrases, and the call/trace/affect/connect stems
  bounded on the right so callus/Connecticut/affectionate don't fire) OR a
  graph-verified code token (inner camelCase, flanked underscore, call form
  name(, or member access x.name; a bare PascalCase word is not a token) →
  full explore in a <codegraph_context> block.
- MEDIUM — plain prose words that match indexed symbol-name segments
  (one name covering >=2 prompt words, or a rare >=4-char segment shared across
  >=2 names) → a short pointer naming the symbols for the agent to query
  itself, never a full explore.
- otherwise silent.

The segment matching is derived at query time from the existing indexed node
names, so no schema change is needed (CURRENT_SCHEMA_VERSION stays 7 and the
golden .schema is byte-identical). The Claude UserPromptSubmit JSON payload
{prompt,cwd} is now parsed (raw-string invocation still works), and
CODEGRAPH_NO_PROMPT_HOOK / CODEGRAPH_PROMPT_HOOK=0 disable the hook.

No telemetry, counters, or tracking of any kind are added. The only new
dependency is unicode-normalization (NFD folding so accented prose matches
ASCII identifier segments); regex was already present transitively. Golden
fixtures and .schema unchanged (no regen).
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.33594% with 29 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/codegraph-cli/src/main.rs 85.71% 10 Missing ⚠️
crates/codegraph-cli/src/segments.rs 94.37% 9 Missing ⚠️
crates/codegraph-cli/src/segment_match.rs 92.07% 8 Missing ⚠️
crates/codegraph-cli/src/structural_gate.rs 99.32% 1 Missing ⚠️
crates/codegraph-store/src/queries.rs 96.29% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (94.33%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #145      +/-   ##
==========================================
- Coverage   95.55%   95.54%   -0.01%     
==========================================
  Files         115      118       +3     
  Lines       57429    57929     +500     
==========================================
+ Hits        54876    55349     +473     
- Misses       2553     2580      +27     
Files with missing lines Coverage Δ
crates/codegraph-mcp/src/engine.rs 97.36% <100.00%> (+<0.01%) ⬆️
crates/codegraph-cli/src/structural_gate.rs 99.32% <99.32%> (ø)
crates/codegraph-store/src/queries.rs 98.18% <96.29%> (-0.03%) ⬇️
crates/codegraph-cli/src/segment_match.rs 92.07% <92.07%> (ø)
crates/codegraph-cli/src/segments.rs 94.37% <94.37%> (ø)
crates/codegraph-cli/src/main.rs 89.20% <85.71%> (-0.02%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sunerpy
sunerpy merged commit 9dd4557 into main Jul 14, 2026
7 checks passed
@sunerpy
sunerpy deleted the feat/upstream-1.4.1-defer-f-prompt-hook-gate branch July 14, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant